# Create your views here.
from mysites.review.models import *
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext

def node_list(request,area=''):
    
    if area=='':
        list = Node.objects.all()
    else:
        list = Node.objects.filter(city=area)
    
    #return render_to_response('message_form.html',{'form':form})
    return render_to_response('nodes.html',locals(),context_instance=RequestContext(request))

def node_save(request):
    form = NodeForm()
    if request.method =='POST':
        message = Node()
        form = MessageForm(request.POST,instance=message)
        if form.is_valid():
            cd = form.cleaned_data
            form.save()
        return render_to_response('node_form.html',locals(),context_instance=RequestContext(request))
    #return render_to_response('message_form.html',{'form':form})
    return render_to_response('node_form.html',locals(),context_instance=RequestContext(request))

def node_view(request,id):
    form = Node.objects.get(id=id);
    return render_to_response('node.html',{'form':form})
    #return render_to_response('node_form.html',locals(),context_instance=RequestContext(request))

def reviews_list(request,id):
    list = Review.object.list()
    
    
def review_save(request):
    form = ReviewForm()
    if request.method =='POST':
        message = Review()
        form = ReviewForm(request.POST,instance=message)
        if form.is_valid():
            cd = form.cleaned_data
            form.save()
        return render_to_response('message_form.html',locals(),context_instance=RequestContext(request))
    #return render_to_response('message_form.html',{'form':form})
    return render_to_response('message_form.html',locals(),context_instance=RequestContext(request))

